<template>
  <div>
    <el-table :data="tableData" stripe border :max-height="maxTableHeight" style="width: 100%">
      <el-table-column type="index" label="序号" width="50" resizable align="center" />
      <el-table-column prop="nickname" label="用户名" resizable show-overflow-tooltip align="center" />
      <el-table-column prop="username" label="姓名" sortable resizable show-overflow-tooltip align="center" />
      <el-table-column prop="avatar" label="人像照片" resizable show-overflow-tooltip align="center" />
      <el-table-column prop="sex" label="性别" resizable show-overflow-tooltip align="center" />
      <el-table-column prop="phone" label="手机号" resizable show-overflow-tooltip align="center" />
      <el-table-column prop="role" label="角色" resizable show-overflow-tooltip align="center" />
      <el-table-column prop="dep" label="部门" resizable show-overflow-tooltip align="center" />
      <el-table-column prop="email" label="邮箱" resizable show-overflow-tooltip align="center" />
      <el-table-column fixed="right" label="操作" width="400" resizable show-overflow-tooltip align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="warning" plain @click="handleEdit(scope.$index, scope.row)">
            编辑
          </el-button>
          <el-button size="mini" type="danger" plain @click="handleDelete(scope.$index, scope.row)">
            删除
          </el-button>
          <el-button size="mini" type="primary" plain @click="handleDetails(scope.$index, scope.row)">
            详情
          </el-button>
          <el-button size="mini" type="warning" plain @click="handleRoles(scope.$index, scope.row)">
            变更角色
          </el-button>
          <el-button size="mini" type="warning" plain @click="handleDeps(scope.$index, scope.row)">
            调整部门
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <edit ref="edit" />

    <!-- 变更角色 -->
    <el-dialog title="变更角色" :visible.sync="roleDialog" width="25%">
      <el-form :model="roleForm" label-width="80px">
        <el-form-item label="角色">
          <el-input v-model="roleForm.role" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="roleDialog = false">取 消</el-button>
        <el-button type="primary" @click="roleDialog = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 调整部门 -->
    <el-dialog title="调整部门" :visible.sync="depDialog" width="30%">
      <el-form :model="depForm" label-width="80px">
        <el-form-item label="部门">
          <el-input v-model="depForm.dep" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="depDialog = false">取 消</el-button>
        <el-button type="primary" @click="depDialog = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>

</template>

<script>
import Edit from './Edit.vue'
export default {
  components: {
    Edit
  },
  props: {
    maxTableHeight: {
      type: String | Number
    },
    tableData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      roleDialog: false,
      depDialog: false,
      roleForm: {
        role: ''
      },
      depForm: {
        dep: ''
      }
    }
  },
  methods: {
    handleEdit() {
      this.$refs.edit.togglePopup(true)
    },
    // 详情
    handleDetails(index, row) {
      this.$router.push({
        name: 'PersonnelDetails',
        params: {
          id: row.id || 1
        }
      })
    },
    // 变更角色
    handleRoles(index, row) {
      this.roleDialog = true
    },
    // 调整部门
    handleDeps(index, row) {
      this.depDialog = true
    }
  }

}
</script>

<style>
</style>
